import {
  fromJS
} from 'immutable'
import {
  GET_HOME_DATA,
  ADD_AIRTICLE_LIST,
  CHANGHE_SHOW_SCROLL
} from './constants'
const defaultState = fromJS({
  topicList: [],
  articleList: [],
  recommendList: [],
  articlePage: 1,
  showScroll: false
})
export default (state = defaultState, action) => {
  switch (action.type) {
    case GET_HOME_DATA:
      return state.merge({
        topicList: fromJS(action.topicList),
        articleList: fromJS(action.articleList),
        recommendList: fromJS(action.recommendList)
      })
    case ADD_AIRTICLE_LIST:
      return state.merge({
        articleList: state.get('articleList').concat(action.list),
        articlePage: fromJS(action.page)
      })
    case CHANGHE_SHOW_SCROLL:
      return state.set('showScroll', action.show)
    default:
      return state
  }
}